package com.lunhui.user.business.impl;

import com.lunhui.user.business.RoseService;
import com.lunhui.user.dal.dao.RoseDao;
import com.lunhui.user.dal.model.Rose;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

/**
 * @author renminghe-kg
 */
@Service("roseService")
public class RoseServiceImpl implements RoseService {
    private static final Logger logger = LoggerFactory.getLogger(RoseServiceImpl.class);

    @Resource
    @Qualifier("roseDao")
    private RoseDao roseDao;


    @Override
    public List<Rose> findRoseIdAndNameListByUserId(Integer userId) throws Exception {
        return roseDao.findRoseIdAndNameListByUserId(userId);
    }

    @Override
    public Integer save(Rose rose) throws Exception {
        try {
            return roseDao.save(rose);
        } catch (SQLException e) {
            logger.error("保存角色信息失败: " + e.getMessage());
            throw new RuntimeException("保存角色信息失败: " + e.getMessage());
        }
    }

    @Override
    public Rose findRoseByUserIdAndRoseName(Integer userId, String roseName) {
        try {
            HashMap<String, Object> paraMap = new HashMap<>();
            paraMap.put("userId", userId);
            paraMap.put("roseName", roseName);

            return roseDao.findRoseByUserIdAndRoseName(paraMap);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }

    @Override
    public Rose findRoseByRoseId(Integer roseId) {
       return roseDao.findRoseByRoseId(roseId);
    }

    @Override
    public void update(Rose rose) {
        try {
            roseDao.update(rose);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}